package com.offcn.user.service.impl;
import com.offcn.bean.User;
import com.offcn.user.dao.UserDao;
import com.offcn.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao userDao;

    @Override
    public List<User> queryUserList() {
        return userDao.selectUserList();
    }

    //实现用户的录入
    @Transactional
    @Override
    public void saveUser(User user) {
        userDao.insertUser(user);
    }

    //实现登录验证
    @Override
    public User queryUserByNameAndPssword(String username, String password) {
        //按照用户名查询用户
        User user = userDao.selectUserByName(username);
        //查到的用户的密码和页面送来的密码进行比对，如果相同则返回用户信息
        if (user != null && user.getPassword().equals(password)){
            return user;
        }

        return null;
    }


}
